﻿namespace ImapComponent.Net.Mail.Imap4
{
    using System;

    /// <summary>
    /// Represents the message uids collection.
    /// </summary>
    public class MessageUidCollection : MessageNumberCollection
    {
        #region Methods

        /// <summary>
        /// Parses the a string which represents a message uid collection to a collection.
        /// </summary>
        /// <param name="messageUidCollectionString">A message uid collection string to parse.</param>
        /// <returns>A message uid collection.</returns>
        public static MessageUidCollection Parse(string messageUidCollectionString)
        {
            MessageUidCollection resultCollection = new MessageUidCollection();

            foreach (string valueOrRange in messageUidCollectionString.Split(','))
            {
                if (valueOrRange.Contains(":"))
                {
                    resultCollection.AddRange(valueOrRange);
                }
                else
                {
                    resultCollection.Add(Int32.Parse(valueOrRange));
                }
            }

            return resultCollection;
        }

        #endregion // Methods
    }
}
